<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2019/7/16
 * Time: 11:03
 */

namespace app\api\controller;


use think\Db;
use think\Exception;
use think\Loader;

class My extends Base
{
    public $create_time; // 创建时间
    public $user_id; // 用户ID
    public $page; // 页码
    
    /**
     * 异地登录验证
     * @return string
     */
    public function __construct()
    {
        $this->create_time = date('Y-m-d H:i:s');
        $this->user_id = input('user_id');
        $this->page = input('page') ? input('page') : 1;
        $time = input('time');
        $value = input('value');
        $reqKey = input('reqKey');
        $auth = $this->checkAll($this->user_id,$time,$value,$reqKey);
        if($auth == 112){
            echo json_encode(['status'=>301,'msg'=>$this->otherLogin]);
            exit;
        }elseif($auth == 110){
            echo json_encode(['status' => 302, 'msg' => $this->frost]);
            exit;
        }elseif($auth == 2111){
            echo json_encode(['status' => 303, 'msg' => $this->del]);
            exit;
        }
    }
    
    /**
     * 学校列表
     * @return \think\response\Json
     * keyword   搜索关键字
     */
    public function schoolList(){
        $keyword = input('keyword');
        $school = Db::table('up_school')
            ->where('sc_status', 1)
            ->where('sc_name', 'like', '%' . $keyword . '%')
            ->field('sc_id, sc_name as name, sc_code')
            ->order('sc_update_time desc')
            ->select();
        if($school){
            return json(['status' => 200, 'msg' => $school]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 根据学校选择社团
     * @return \think\response\Json
     * school_id   学校ID
     * page  页码
     */
    public function selectAssn(){
        $school_id = input('school_id');
        $assnList = Db::table('up_assn')
            ->field('assn_id, assn_name')
            ->where('assn_school', $school_id)
            ->page($this->page, 10)
            ->order('assn_time desc')
            ->select();
        if($assnList){
            return json(['status' => 200, 'msg' => $assnList]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 用户选择角色
     * @return \think\response\Json
     * role_user_type         角色类型
     *                          1 国防退役大学生  2 国防大学生  3 其他社团退役大学生
     *                          4 其他社团大学生  5 企事业在职  6 教师  7 自媒体
     *                          8 无社团退役大学生  9 无社团非退役大学生
     * role_user_card         身份证号
     * role_user_school       学校ID
     * role_user_st           社团ID
     * role_user_student_img  学生证或者毕业证
     * role_user_leave_img    退伍证
     * role_user_onjob_img    企事业在职证明
     * role_user_teacher_img  教师证
     * role_user_code         学号
     * role_user_front_img    身份证正面
     * role_user_back_img     身份证背面
     * role_user_company      工作单位
     * role_video_type        自媒体类型   1 校内  2 校外
     */
    public function chooseRole(){
        $role_user_type = input('role_user_type'); // 角色类型
        $role_user_card = input('role_user_card'); // 身份证号
        $role_user_school = input('role_user_school'); // 学校ID
        $role_user_st = input('role_user_st'); // 社团ID
        $role_user_student_img = input('role_user_student_img'); // 学生证或毕业证
        $role_user_leave_img = input('role_user_leave_img'); // 退伍证
        $role_user_onjob_img = input('role_user_onjob_img'); // 企事业在职证明
        $role_user_teacher_img = input('role_user_teacher_img'); // 教师证
        $role_user_code = input('role_user_code'); // 学号
        $role_user_front_img = input('role_user_front_img'); // 身份证正面
        $role_user_back_img = input('role_user_back_img'); // 身份证背面
        $role_user_company = input('role_user_company'); // 工作单位
        $role_video_type = input('role_video_type'); // 自媒体类型  1 校内   2 校外
        $data = [];
        if($role_user_type == 1 || $role_user_type == 3){ // 国防退役大学生 或 其他社团退役大学生
            if(empty($role_user_student_img)) return json(['status' => 0, 'msg' => '请上传学生证']);
            if(empty($role_user_leave_img)) return json(['status' => 0, 'msg' => '请上传退伍证']);
            $data = [
                'role_user_card' => $role_user_card,
                'role_user_school' => $role_user_school,
                'role_user_st' => $role_user_st,
                'role_user_student_img' => $role_user_student_img,
                'role_user_leave_img' => $role_user_leave_img
            ];
        }elseif($role_user_type == 2 || $role_user_type == 4){ // 国防大学生 活 其他社团大学生
            if(empty($role_user_student_img)) return json(['status' => 0, 'msg' => '请上传学生证']);
            $data = [
                'role_user_card' => $role_user_card,
                'role_user_school' => $role_user_school,
                'role_user_st' => $role_user_st,
                'role_user_student_img' => $role_user_student_img,
            ];
        }elseif($role_user_type == 5){ // 企事业在职
            if(empty($role_user_onjob_img)) return json(['status' => 0, 'msg' => '请上传在职证明']);
            $data['role_user_onjob_img'] = $role_user_onjob_img;
        }elseif($role_user_type == 6){ // 教师
            if(empty($role_user_teacher_img)) return json(['status' => 0, 'msg' => '请上传教师证']);
            $data['role_user_teacher_img'] = $role_user_teacher_img;
        }elseif($role_user_type == 7){ // 自媒体
            if(empty($role_user_front_img)) return json(['status' => 0, 'msg' => '请上传身份证正面']);
            if(empty($role_user_back_img)) return json(['status' => 0, 'msg' => '请上传身份证背面']);
            if($role_video_type == 1){ // 校内
                $data = [
                    'role_user_st' => $role_user_st,
                    'role_user_school' => $role_user_school,
                    'role_user_code' => $role_user_code,
                ];
            }else{ // 校外
                $data = [
                    'role_user_company' => $role_user_company,
                ];
            }
            $data['role_video_type'] = $role_video_type;
            $data['role_user_front_img'] = $role_user_front_img;
            $data['role_user_back_img'] = $role_user_back_img;
        }elseif($role_user_type == 8){ // 无社团退役
            if(empty($role_user_student_img)) return json(['status' => 0, 'msg' => '请上传学生证']);
            if(empty($role_user_leave_img)) return json(['status' => 0, 'msg' => '请上传退伍证']);
            $data = [
                'role_user_card' => $role_user_card,
                'role_user_school' => $role_user_school,
                'role_user_student_img' => $role_user_student_img,
                'role_user_leave_img' => $role_user_leave_img
            ];
        }else{ // 无社团非退役
            if(empty($role_user_student_img)) return json(['status' => 0, 'msg' => '请上传学生证']);
            $data = [
                'role_user_card' => $role_user_card,
                'role_user_school' => $role_user_school,
                'role_user_student_img' => $role_user_student_img,
            ];
        }
        
        $data['role_user_id'] = $this->user_id;
        $data['role_user_type'] = $role_user_type;
        $data['role_time'] = date('Y-m-d H:i:s');

        $isHave = Db::table('up_user_role')
            ->where('role_user_id', $this->user_id)
            ->where('role_user_type', $role_user_type)
            ->find();
        if($isHave){ // 如果有就更新
            $data['role_audit_status'] = 1;
            $data['role_false_reason'] = null;
            $res = Db::table('up_user_role')->where('role_id', $isHave['role_id'])->update($data);
        }else{
            $res = Db::table('up_user_role')->insert($data);
        }
        
        if($res){
            return json(['status' => 200, 'msg' => '操作成功']);
        }else{
            return json(['status' => 0, ',msg' => '操作失败']);
        }
    }
    
    /**
     * 角色申请页面展示
     * @return \think\response\Json
     * role_type  类型
     */
    public function roleShow(){
        $list = Db::table('up_user_role')
            ->join('up_school', 'sc_id = role_user_school', 'left')
            ->join('up_assn', 'assn_id = role_user_st', 'left')
            ->field('role_user_card, assn_name, sc_name, role_user_student_img, role_user_leave_img, 
            role_user_onjob_img, role_user_teacher_img, role_user_code, role_user_front_img, role_user_back_img, 
            role_audit_status, role_false_reason, role_id, role_user_school, role_user_st, role_user_company, role_video_type')
            ->where('role_user_id', $this->user_id)
            ->where('role_user_type', input('role_type'))
            ->find();
        if($list){
            return json(['status' => 200, 'msg' => $list]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 用户名称和头像信息
     * @return \think\response\Json
     */
    public function userBaseInfo(){
        if(isset($_POST['other_id']) && $_POST['other_id']){
            $this->user_id = $_POST['other_id'];
        }
        $field = 'user_username, user_image, user_is_send,user_district_str';
        $userInfo = $this->userInfo($field);
        if($userInfo){
            return json(['status' => 200, 'msg' => $userInfo]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 用户详情
     * @return \think\response\Json
     * page  页码
     * PS：如果是看其他人的信息，比如从社团处点进来的，有other_id
     */
    public function userDetail(){
        //1、是不是点击别人进来的,改id值 start ------------------------------------------------------
        $user_id = $this->user_id;
        if(isset($_POST['other_id']) && $_POST['other_id']){
            $this->user_id = $_POST['other_id'];
        }
        //---是不是点击别人进来的,改id值 end -------------------------------------------------------
        $field = 'user_username, user_image, user_district_str, user_intro, user_video, user_images, user_phone, 
        user_gender, user_birthday';
        $detail = $this->userInfo($field);
        $images_array = explode(',', $detail['user_images']);
        if(empty($detail['user_video'])){
            $video_img = array_slice($images_array, 0, 3);
        }else{
            $video_array = explode(' ', $detail['user_video']);
            $video_imgs = array_merge($video_array, $images_array);
            $video_img = array_slice($video_imgs, 0, 3);
        }
        $detail['video_img'] = $video_img;
        // 年龄
        $detail['user_age'] = $this->getAge($detail['user_birthday']);
        
        if($detail){
            $detail['user_id'] = $this->user_id; // app用
            // 帖子
            $love_post = Db::table('up_love_post')
                ->field('post_id, post_content, post_img, post_is_top, post_date, post_user_id, 
                is_show_user')
                ->where('post_user_id', $this->user_id)
                ->where('post_status', 1)
//            ->where('post_is_report', 1)
                ->order('post_is_top desc, post_create_time desc')
                ->page($this->page, 10)
                ->select();
            if($love_post){
                foreach($love_post as $k => $v){
                    // 图片
                    if(!empty($v['post_img'])){
                        $love_post[$k]['post_img'] = explode(',', trim($v['post_img'], ','));
                    }else{
                        $love_post[$k]['post_img'] = [];
                    }
                    // 评论数
                    $count = Db::table('up_comment')
                        ->where('type', 3)
                        ->where('f_id', $v['post_id'])
                        ->count();
                    $love_post[$k]['count'] = $count;
                    // 是否置顶
                    if($v['post_is_top'] == 2){
                        $love_post[$k]['top'] = '置顶';
                    }else{
                        $love_post[$k]['top'] = '';
                    }
                }
            }
            $detail['post'] = $love_post;
            //2、是不是点击别人进来的，增加额外信息 start------------------------------------------------------
            if(isset($_POST['other_id']) && $_POST['other_id']){
                if($_POST['other_id'] != $user_id){
                    //2-1，可以不可以点击添加好友和发消息及仨点功能的按钮
                    $where = array();
                    $where['friend_user_id'] = $user_id;
                    $where['friend_other_user'] = $_POST['other_id'];
                    $have = Db::table('up_friend')
                        ->where($where)
                        ->find();
                    $friend_status = 0; //不是好友或没有过操作，可以添加（判断在添加里）
                    if($have && $have['friend_status'] == 2){
                        $friend_status = 1; //已经是好友，不可以添加，但是有仨点和发消息
                        $detail['friend_remark'] = $have['friend_remark'];
                    }
                    //2-2，有没有关注
                    $where = array();
                    $where['user_id'] = $user_id;
                    $where['like_user_id'] = $_POST['other_id'];
                    $have2 = Db::table('up_like')
                        ->where($where)
                        ->find();
                    $like_status = 0; //没有关注，显示关注
                    if($have2){
                        $like_status = 1; //已关注，显示已关注
                    }
                    $detail['friend_status'] = $friend_status;
                    $detail['like_status'] = $like_status;
                }else{
                    //说明是点到自己了，为2则都不展示
                    $detail['friend_status'] = 2;
                    $detail['like_status'] = 2;
                }
            }
            //----是不是点击别人进来的，增加额外信息 end-------------------------------------------------------

            return json(['status' => 200, 'msg' => $detail]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 用户查看更多视频、图片介绍
     * @return \think\response\Json
     */
    public function videoImgDetail(){
        // 如果看的是别人的
        $other_id = input('other_id');
        if(isset($other_id) && $other_id != ''){
            $this->user_id = $other_id;
        }
        $field = 'user_video, user_images';
        $intro = $this->userInfo($field);
        if($intro){
            $intro['user_images'] = array_filter(explode(',',$intro['user_images']));
            return json(['status' => 200, 'msg' => $intro]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 编辑用户视频和图片
     * @return \think\response\Json
     * user_video    视频
     * user_images   图片
     */
    public function updateVideoImg(){
        $user_video = input('user_video');
        $user_images = input('user_images');
        $update = [
            'user_video' => $user_video,
            'user_images' => $user_images
        ];
        $res = Db::table('up_u_user')->where('user_id', $this->user_id)->update($update);
        if($res){
            return json(['status' => 200, 'msg' => '编辑成功']);
        }else{
            return json(['status' => 0, 'msg' => '编辑失败']);
        }
    }
    
    /**
     * 用户编辑信息时的回显
     * @return \think\response\Json
     */
    public function userUpdateInfo(){
        $field = 'user_username, user_image, user_birthday, user_gender, user_intro, user_district_str, 
        user_intro_update';
        $info = $this->userInfo($field);
        if($info){
            if($info['user_gender'] == 1){
                $info['sex'] = '男';
            }elseif($info['user_gender'] == 2){
                $info['sex'] = '女';
            }else{
                $info['sex'] = '保密';
            }
            return json(['status' => 200, 'msg' => $info]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 编辑用户资料
     * @return \think\response\Json
     * user_image     用户头像
     * user_username  用户名
     * user_gender    用户性别    1 男   2 女   3 保密
     * user_birthday  用户生日
     * user_intro     用户简介
     * user_sheng     省份
     * user_shi       城市
     * user_qu        地区
     */
    public function updateUserInfo(){
        $params = input('param.');
        $update = [];
        if(isset($params['user_image'])) $update['user_image'] = $params['user_image'];
        if(isset($params['user_username'])) $update['user_username'] = $params['user_username'];
        if(isset($params['user_gender'])) $update['user_gender'] = $params['user_gender'];
        if(isset($params['user_birthday'])) $update['user_birthday'] = $params['user_birthday'];
        if(isset($params['user_intro'])){
            $update['user_intro'] = $params['user_intro'];
            $update['user_intro_update'] = date('Y-m-d');
        }
        if(isset($params['user_sheng']) && isset($params['user_shi']) && isset($params['user_qu'])){
            $update['user_sheng'] = $params['user_sheng'];
            $update['user_shi'] = $params['user_shi'];
            $update['user_qu'] = $params['user_qu'];
            $districtStr = $this->districtStr($params['user_sheng'], $params['user_shi'], $params['user_qu']);
            $update['user_district_str'] = $districtStr;
        }
        $res = Db::table('up_u_user')->where('user_id', $this->user_id)->update($update);
        if($res){
            return json(['status' => 200, 'msg' => '编辑成功']);
        }else{
            return json(['status' => 0, 'msg' => '编辑失败']);
        }
    }
    
    /**
     * 置顶/取消置顶
     * @return \think\response\Json
     * post_id   帖子ID
     */
    public function setTop(){
        $post_id = input('post_id');
        
        $isTop = Db::table('up_love_post')->where('post_id', $post_id)->value('post_is_top');
        if($isTop == 1){
            // 最多15个置顶
            $count = Db::table('up_love_post')
                ->where('post_user_id', $this->user_id)
                ->where('post_status', 1)
                ->where('post_is_top', 2)
//            ->where('post_is_report', 1)
                ->count('post_id');
            
            if($count >= 15){
                return json(['status' => 0, 'msg' => '置顶帖子不得超过15条']);
            }
            $top = 2;
        }else{
            $top = 1;
        }
        $res = Db::table('up_love_post')->where('post_id', $post_id)->setField('post_is_top', $top);
        if($res){
            return json(['status' => 200, 'msg' => '设置成功']);
        }else{
            return json(['status' => 0, 'msg' => '设置失败']);
        }
    }
    
    /**
     * 删除帖子
     * @return \think\response\Json
     */
    public function delPost(){
        $post_id = input('post_id');
        $res = Db::table('up_love_post')->where('post_id', $post_id)->setField('post_status', 2);
        if($res){
            return json(['status' => 200, 'msg' => '删除成功']);
        }else{
            return json(['status' => 0, 'msg' => '删除失败']);
        }
    }
    
    /**
     * 消息提醒按钮
     * @return \think\response\Json
     * is_send  是否开启消息提醒  1 开启  2 关闭
     */
    public function messageRemind(){
        $is_send = input('is_send'); // 1 开启    2 关闭
        $res = Db::table('up_u_user')->where('user_id', $this->user_id)->setField('user_is_send', $is_send);
        if($res){
            return json(['status' => 200, 'msg' => '操作成功']);
        }else{
            return json(['status' => 0, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 意见反馈
     * @return \think\response\Json0
     * content   反馈内容
     * phone     联系方式
     */
    public function feedback(){
        $content = input('content');
        $phone = input('phone');
        $inserte = [
            'f_user_id' => $this->user_id,
            'feedback_phone' => $phone,
            'feedback_content' => $content,
            'feedback_time' => $this->create_time
        ];
        $res = Db::table('up_feedback')->insert($inserte);
        if($res){
            return json(['status' => 200, 'msg' => '提交成功']);
        }else{
            return json(['status' => 0, 'msg' => '提交失败']);
        }
    }
    
    /**
     * 我的发布
     * @return \think\response\Json
     * page   页码
     * publish_type    发布的类型    1 资讯   2 老兵自主问答论坛   3 老兵政策解读与案例分享论坛
     *                              4 自媒体论坛  5 军婚军恋   6 考研升学论坛   7 自训教官论坛
     *                              8 悬赏问答   9 短视频
     * son_type         当发布类型为2老兵自主问答论坛时，传此值   1 政策解读   2 答疑解惑
     */
    public function myInformation(){
        $publish_type = input('publish_type');
        if($publish_type == 1){ // 资讯
            $list = Db::table('up_information')
                ->join('up_u_user', 'user_id = information_user_id', 'left')
                ->field('information_id, information_title, information_thumb, information_content, information_fa_time, 
                user_username')
                ->where('information_user_id', $this->user_id)
                ->where('is_admin', 1)
                ->where('is_publish', 1)
                ->order('information_week desc')
                ->page($this->page, 10)
                ->select();
        }elseif($publish_type == 2){ // 老兵自主问答论坛
            $son_type = input('son_type'); // 1 政策解读  2 答疑解惑
            $list = Db::table('up_old_forum')
                ->field('old_forum_id, old_forum_title, old_forum_time')
                ->where('old_forum_user_id', $this->user_id)
                ->where('old_forum_type', $son_type)
                ->where('is_publish', 1)
                ->order('old_forum_time desc')
                ->page($this->page, 10)
                ->select();
            if($list){
                foreach($list as $k => $v){
                    $count = Db::table('up_old_answer')->where('f_id', $v['old_forum_id'])->count();
                    $answer = Db::table('up_old_answer')
                        ->field('old_answer_content, old_answer_video, old_answer_img')
                        ->where('f_id', $v['old_forum_id'])
                        ->order('old_answer_time desc')
                        ->find();
                    $list[$k]['answer_num'] = $count;
                    $list[$k]['answer'] = $answer;
                }
            }
        }elseif($publish_type == 3){ // 老兵政策解读与案例分享论坛
            $list = Db::table('up_share')
                ->join('up_u_user', 'user_id = share_user_id', 'left')
                ->field('share_id, share_title, share_content, share_time, share_url, user_username')
                ->where('share_user_id', $this->user_id)
                ->where('is_publish', 1)
                ->order('share_time desc')
                ->page($this->page, 10)
                ->select();
        }elseif($publish_type == 4){ // 自媒体论坛
            $list = Db::table('up_media')
                ->join('up_u_user', 'user_id = media_user_id', 'left')
                ->field('media_id, media_title, media_content, media_time, media_url, media_url_thumb, 
                user_username')
                ->where('media_user_id', $this->user_id)
                ->where('is_admin', 1)
                ->where('is_publish', 1)
                ->order('media_time desc')
                ->page($this->page, 10)
                ->select();
        }elseif($publish_type == 5){ // 军婚军恋
            $list = Db::table('up_love_post')
                ->join('up_u_user', 'user_id = post_user_id', 'left')
                ->field('post_id, post_content, post_img, post_create_time, user_username, 
                user_image')
                ->where('post_user_id', $this->user_id)
                ->where('post_status', 1)
                ->where('is_publish', 1)
                ->order('post_create_time desc')
                ->page($this->page, 10)
                ->select();
            if($list){
                foreach($list as $k => $v){
                    $count = Db::table('up_comment')
                        ->where('type', 3)
                        ->where('f_id', $v['post_id'])
                        ->count();
                    $list[$k]['count'] = $count;
                }
            }
        }elseif($publish_type == 6){ // 考研升学论坛
            $list = Db::table('up_go_school')
                ->join('up_u_user', 'user_id = media_user_id', 'left')
                ->field('media_id, media_title, media_content, media_time, media_url, media_url_thumb, 
                user_username')
                ->where('media_user_id', $this->user_id)
                ->where('is_publish', 1)
                ->order('media_time desc')
                ->page($this->page, 10)
                ->select();
        }elseif($publish_type == 7){ // 自训教官论坛
            $list = Db::table('up_instructor')
                ->join('up_u_user', 'user_id = media_user_id', 'left')
                ->field('media_id, media_title, media_content, media_time, media_url, media_url_thumb, 
                user_username')
                ->where('media_user_id', $this->user_id)
                ->where('is_publish', 1)
                ->order('media_time desc')
                ->page($this->page, 10)
                ->select();
        }elseif($publish_type == 8){ // 悬赏问答
            $list = Db::table('up_answer')
                ->field('answer_id, answer_title, answer_time')
                ->where('answer_user_id', $this->user_id)
                ->where('is_publish', 1)
                ->order('answer_time desc')
                ->page($this->page, 10)
                ->select();
            if($list){
                foreach($list as $k => $v){
                    $count = Db::table('up_answer_reply')->where('f_id', $v['answer_id'])->count();
                    $answer = Db::table('up_answer_reply')
                        ->where('f_id', $v['answer_id'])
                        ->order('reply_answer_time desc')
                        ->find();
                    $list[$k]['answer_num'] = $count;
                    $list[$k]['answer'] = $answer;
                }
            }
        }else{ // 短视频
            $list = Db::table('up_video')
                ->join('up_u_user', 'user_id = video_user_id', 'left')
                ->field('video_id, video_url, video_img, videourl, user_username, user_image')
                ->where('video_user_id', $this->user_id)
                ->order('video_time desc')
                ->page($this->page, 10)
                ->select();
        }
        
        return json(['status' => 200, 'msg' => $list]);
    }
    
    /**
     * 我的草稿箱
     * @return \think\response\Json
     * page   页码
     * publish_type    发布的类型    1 资讯   2 老兵自主问答论坛   3 老兵政策解读与案例分享论坛
     *                              4 自媒体论坛  5 军婚军恋   6 考研升学论坛   7 自训教官论坛
     *                              8 悬赏问答
     * son_type         当发布类型为2老兵自主问答论坛时，传此值   1 政策解读   2 答疑解惑
     */
    public function myDrafts(){
        $publish_type = input('publish_type');
        if($publish_type == 1){ // 资讯
            $list = Db::table('up_information')
                ->join('up_u_user', 'user_id = information_user_id', 'left')
                ->field('information_id, information_title, information_thumb, information_content, information_fa_time, 
                user_username')
                ->where('information_user_id', $this->user_id)
                ->where('is_admin', 1)
                ->where('is_publish', 2)
                ->order('information_week desc')
                ->page($this->page, 10)
                ->select();
        }elseif($publish_type == 2){ // 老兵自主问答论坛
            $son_type = input('son_type'); // 1 政策解读  2 答疑解惑
            $list = Db::table('up_old_forum')
                ->field('old_forum_id, old_forum_title, old_forum_time')
                ->where('old_forum_user_id', $this->user_id)
                ->where('old_forum_type', $son_type)
                ->where('is_publish', 2)
                ->order('old_forum_time desc')
                ->page($this->page, 10)
                ->select();
            if($list){
                foreach($list as $k => $v){
                    $count = Db::table('up_old_answer')->where('f_id', $v['old_forum_id'])->count();
                    $answer = Db::table('up_old_answer')
                        ->field('old_answer_content, old_answer_video, old_answer_img')
                        ->where('f_id', $v['old_forum_id'])
                        ->order('old_answer_time desc')
                        ->find();
                    $list[$k]['answer_num'] = $count;
                    $list[$k]['answer'] = $answer;
                }
            }
        }elseif($publish_type == 3){ // 老兵政策解读与案例分享论坛
            $list = Db::table('up_share')
                ->join('up_u_user', 'user_id = share_user_id', 'left')
                ->field('share_id, share_title, share_content, share_time, share_url, user_username')
                ->where('share_user_id', $this->user_id)
                ->where('is_publish', 2)
                ->order('share_time desc')
                ->page($this->page, 10)
                ->select();
        }elseif($publish_type == 4){ // 自媒体论坛
            $list = Db::table('up_media')
                ->join('up_u_user', 'user_id = media_user_id', 'left')
                ->field('media_id, media_title, media_content, media_time, media_url, media_url_thumb, 
                user_username')
                ->where('media_user_id', $this->user_id)
                ->where('is_admin', 1)
                ->where('is_publish', 2)
                ->order('media_time desc')
                ->page($this->page, 10)
                ->select();
        }elseif($publish_type == 5){ // 军婚军恋
            $list = Db::table('up_love_post')
                ->join('up_u_user', 'user_id = post_user_id', 'left')
                ->field('post_id, post_content, post_img, post_create_time, user_username, 
                user_image')
                ->where('post_user_id', $this->user_id)
                ->where('post_status', 1)
                ->where('is_publish', 2)
                ->order('post_create_time desc')
                ->page($this->page, 10)
                ->select();
            if($list){
                foreach($list as $k => $v){
                    $count = Db::table('up_comment')
                        ->where('type', 3)
                        ->where('f_id', $v['post_id'])
                        ->count();
                    $list[$k]['count'] = $count;
                }
            }
        }elseif($publish_type == 6){ // 考研升学论坛
            $list = Db::table('up_go_school')
                ->join('up_u_user', 'user_id = media_user_id', 'left')
                ->field('media_id, media_title, media_content, media_time, media_url, media_url_thumb, 
                user_username')
                ->where('media_user_id', $this->user_id)
                ->where('is_publish', 2)
                ->order('media_time desc')
                ->page($this->page, 10)
                ->select();
        }elseif($publish_type == 7){ // 自训教官论坛
            $list = Db::table('up_instructor')
                ->join('up_u_user', 'user_id = media_user_id', 'left')
                ->field('media_id, media_title, media_content, media_time, media_url, media_url_thumb, 
                user_username')
                ->where('media_user_id', $this->user_id)
                ->where('is_publish', 2)
                ->order('media_time desc')
                ->page($this->page, 10)
                ->select();
        }else{ // 悬赏问答
            $list = Db::table('up_answer')
                ->field('answer_id, answer_title, answer_time')
                ->where('answer_user_id', $this->user_id)
                ->where('is_publish', 2)
                ->order('answer_time desc')
                ->page($this->page, 10)
                ->select();
            if($list){
                foreach($list as $k => $v){
                    $count = Db::table('up_answer_reply')->where('f_id', $v['answer_id'])->count();
                    $answer = Db::table('up_answer_reply')
                        ->where('f_id', $v['answer_id'])
                        ->order('reply_answer_time desc')
                        ->find();
                    $list[$k]['answer_num'] = $count;
                    $list[$k]['answer'] = $answer;
                }
            }
        }
    
        return json(['status' => 200, 'msg' => $list]);
    }
    
    
    //*************************  草稿箱回显 start **********************//
    
    /**
     * 回显资讯
     * @return \think\response\Json
     * information_id    资讯ID
     */
    public function showInformation(){
        $information_id = input('information_id');
        $info = Db::table('up_information')
            ->join('up_interest', 'information_type_id = interest_id', 'left')
            ->where('information_id', $information_id)
            ->field('information_id, information_title, information_content, is_show_user, 
            information_type_id, interest_word')
            ->find();
        return json(['status' => 200, 'msg' => $info]);
    }
    
    /**
     * 回显老兵自主问答论坛
     * @return \think\response\Json
     * old_forum_id     ID
     * old_forum_type   类型     1 政策解读   2 答疑解惑
     */
    public function showOldAnswer(){
        $old_forum_id = input('old_forum_id');
        $old_forum_type = input('old_forum_type'); // 1 政策解读   2 答疑解惑
        $info = Db::table('up_old_forum')
            ->where('old_forum_id', $old_forum_id)
            ->where('old_forum_type', $old_forum_type)
            ->field('old_forum_id, old_forum_title, old_forum_content, old_forum_video, old_forum_img, 
            is_show_user')
            ->find();
        return json(['status' => 200, 'msg' => $info]);
    }
    
    /**
     * 回显老兵政策解读与案例分享论坛
     * @return \think\response\Json
     * share_id     分享ID
     */
    public function showShare(){
        $share_id = input('share_id');
        $info = Db::table('up_share')
            ->join('up_share_type', 'share_type_id = f_id', 'left')
            ->where('share_id', $share_id)
            ->field('share_id, share_title, share_content, f_id, share_url, is_show_user, share_type_name')
            ->find();
        return json(['status' => 200, 'msg' => $info]);
    }
    
    /**
     * 回显自媒体
     * @return \think\response\Json
     * media_id     自媒体ID
     */
    public function showMedia(){
        $media_id = input('media_id');
        $info = Db::table('up_media')
            ->where('media_id', $media_id)
            ->field('media_id, media_title, media_content, media_url, media_url_thumb, is_show_user')
            ->find();
        return json(['status' => 200, 'msg' => $info]);
    }
    
    /**
     * 回显军婚军恋
     * @return \think\response\Json
     * post_id     帖子ID
     */
    public function showLove(){
        $post_id = input('post_id');
        $info = Db::table('up_love_post')
            ->where('post_id', $post_id)
            ->field('post_id, post_content, post_img, is_show_user')
            ->find();
        return json(['status' => 200, 'msg' => $info]);
    }
    
    /**
     * 回显考研升学
     * @return \think\response\Json
     * kao_id     ID
     */
    public function showKao(){
        $media_id = input('kao_id');
        $info = Db::table('up_go_school')
            ->where('media_id', $media_id)
            ->field('media_id, media_title, media_content, media_url, media_url_thumb, is_show_user')
            ->find();
        return json(['status' => 200, 'msg' => $info]);
    }
    
    /**
     * 回显自训教官
     * @return \think\response\Json
     * media_id    ID
     */
    public function showSelf(){
        $media_id = input('media_id');
        $info = Db::table('up_instructor')
            ->where('media_id', $media_id)
            ->field('media_id, media_title, media_content, media_url, media_url_thumb, is_show_user')
            ->find();
        return json(['status' => 200, 'msg' => $info]);
    }
    
    /**
     * 回显悬赏问答
     * @return \think\response\Json
     * answer_id    悬赏问答ID
     */
    public function showAnswer(){
        $answer_id = input('answer_id');
        $info = Db::table('up_answer')
            ->where('answer_id', $answer_id)
            ->field('answer_id, answer_title, answer_describe, answer_img, answer_video, is_show_user')
            ->find();
        return json(['status' => 200, 'msg' => $info]);
    }
    
    //*************************  草稿箱回显 end **********************//
    
    //*************************  草稿箱操作 start **********************//
    
    /**
     * 草稿箱资讯操作
     * @return \think\response\Json
     * information_id       资讯ID
     * do_type              1 发布   2 保存
     * is_show_user         1 不匿名   2 匿名
     * title                标题
     * content              内容
     * information_url      视频/图片地址
     * information_type_id  资讯分类
     */
    public function doInformation(){
        $information_id = input('information_id');
        $do_type = input('do_type'); // 1 发布   2 保存
        $is_show_user = input('is_show_user'); // 是否匿名  1 不匿名   2 匿名
        $title = input('title');
        $title = $this->sensitive($title); // 敏感词过滤
        $content = input('content');
        $content = $this->sensitive($content);
        $information_url = input('param.information_url');
        $information_type_id = input('param.information_type_id');
        
        $update = [
            'information_title' => $title,
            'information_type_id' => $information_type_id,
            'information_content' => $content,
            'information_url' => $information_url,
            'information_time' => date('Y-m-d H:i:s'),
            'is_show_user' => $is_show_user
        ];
        $img = explode(',', $information_url);
        $update['information_thumb'] = $img[0];
        // 如果是发布，则改变资讯状态
        if($do_type == 1){
            $update['is_publish'] = 1;
        }
        $res = Db::table('up_information')->where('information_id', $information_id)->update($update);
        if($res){
            return json(['status' => 200, 'msg' => '操作成功']);
        }else{
            return json(['status' => 0, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 草稿箱老兵自主问答论坛操作
     * @return \think\response\Json
     * old_forum_id     ID
     * do_type          操作类型    1 发布   2 保存
     * is_show_user     是否匿名    1 不匿名  2 匿名
     * title            标题
     * describe         内容
     * img              图片
     * video            视频
     */
    public function doOldAnswer(){
        $old_forum_id = input('old_forum_id');
        $do_type = input('do_type'); // 1 发布   2 保存
        $is_show_user = input('is_show_user'); // 是否匿名  1 不匿名   2 匿名
        $title = input('title');
        $title = $this->sensitive($title);
        $answer_describe = input('describe');
        $answer_describe = $this->sensitive($answer_describe);
        $img = input('img');
        $video = input('video');
        
        $update = [
            'old_forum_title' => $title,
            'old_forum_content' => $answer_describe,
            'old_forum_video' => $video,
            'old_forum_img' => $img,
            'is_show_user' => $is_show_user,
            'old_update_time' => date('Y-m-d H:i:s')
        ];
        if($do_type == 1){
            $update['old_forum_time'] = date('Y-m-d H:i:s');
            $update['is_publish'] = 1;
        }
        
        $res = Db::table('up_old_forum')->where('old_forum_id', $old_forum_id)->update($update);
        if($res){
            return json(['status' => 200, 'msg' => '操作成功']);
        }else{
            return json(['status' => 0, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 草稿箱老兵政策解读与案例分享论坛操作
     * @return \think\response\Json
     * share_id     ID
     * do_type      操作类型    1 发布   2 保存
     * is_show_user 是否匿名    1 不匿名   2 匿名
     * title        标题
     * content      内容
     * type_id      类型ID
     * img_url      图片
     */
    public function doShare(){
        $share_id = input('share_id');
        $do_type = input('do_type'); // 1 发布   2 保存
        $is_show_user = input('is_show_user'); // 是否匿名  1 不匿名   2 匿名
        $title = input('title');
        $title = $this->sensitive($title);
        $content = input('content');
        $content = $this->sensitive($content);
        $type_id = input('type_id');
        $img_url = input('img_url');
        
        $update = [
            'share_title' => $title,
            'share_content' => $content,
            'f_id' => $type_id,
            'share_url' => $img_url,
            'is_show_user' => $is_show_user,
            'share_update_time' => date('Y-m-d H:i:s')
        ];
        if($do_type == 1){
            $update['share_time'] = date('Y-m-d H:i:s');
            $update['is_publish'] = 1;
        }
        
        $res = Db::table('up_share')->where('share_id', $share_id)->update($update);
        if($res){
            return json(['status' => 200, 'msg' => '操作成功']);
        }else{
            return json(['status' => 0, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 草稿箱自媒体操作
     * @return \think\response\Json
     * media_id       ID
     * do_type        操作类型   1 发布   2 保存
     * is_show_user   是否匿名   1 不匿名   2 匿名
     * title          标题
     * content        内容
     * img            图片
     */
    public function doMedia(){
        $media_id = input('media_id');
        $do_type = input('do_type'); // 1 发布   2 保存
        $is_show_user = input('is_show_user'); // 是否匿名  1 不匿名   2 匿名
        $title  = input('title');
        $title  = $this->sensitive($title);
        $content  = input('content');
        $content  = $this->sensitive($content);
        $media_url  = input('img');
        
        $update = [
            'media_title' => $title,
            'media_content' => $content,
            'media_url' => $media_url,
            'media_update_time' => date('Y-m-d H:i:s'),
            'is_show_user' => $is_show_user
        ];
        $img = explode(',',$media_url);
        $update['media_url_thumb'] =$img[0];
        if($do_type == 1){
            $update['media_time'] = date('Y-m-d H:i:s');
            $update['is_publish'] = 1;
        }
        
        $res = Db::table('up_media')->where('media_id', $media_id)->update($update);
        if($res){
            return json(['status' => 200, 'msg' => '操作成功']);
        }else{
            return json(['status' => 0, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 草稿箱军婚军恋操作
     * @return \think\response\Json
     * post_id      帖子ID
     * do_type      操作类型    1 发布   2 保存
     * is_show_user 是否匿名    1 不匿名   2 匿名
     * content      内容
     * img          图片
     */
    public function doLove(){
        $post_id = input('post_id');
        $do_type = input('do_type'); // 1 发布   2 保存
        $is_show_user = input('is_show_user'); // 是否匿名  1 不匿名   2 匿名
        $content = input('content');
        $content = $this->sensitive($content);
        $img = input('img');
        
        $update = [
            'post_content' => $content,
            'post_img' => $img,
            'post_update_time' => date('Y-m-d H:i:s'),
            'is_show_user' => $is_show_user
        ];
        if($do_type == 1){
            $update['post_create_time'] = date('Y-m-d H:i:s');
            $update['post_date'] = date('Y-m-d');
            $update['is_publish'] = 1;
        }
        
        $res = Db::table('up_love_post')->where('post_id', $post_id)->update($update);
        if($res){
            return json(['status' => 200, 'msg' => '操作成功']);
        }else{
            return json(['status' => 0, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 草稿箱考研升学操作
     * @return \think\response\Json
     * media_id       ID
     * do_type        操作类型   1 发布   2 保存
     * is_show_user   是否匿名   1 不匿名   2 匿名
     * title          标题
     * content        内容
     * img            图片
     */
    public function doKao(){
        $media_id = input('media_id');
        $do_type = input('do_type'); // 1 发布   2 保存
        $is_show_user = input('is_show_user'); // 是否匿名  1 不匿名   2 匿名
        $title  = input('title');
        $title  = $this->sensitive($title);
        $content  = input('content');
        $content  = $this->sensitive($content);
        $media_url  = input('img');
        
        $update = [
            'media_title' => $title,
            'media_content' => $content,
            'media_url' => $media_url,
            'media_update_time' => date('Y-m-d H:i:s'),
            'is_show_user' => $is_show_user
        ];
        $img = explode(',',$media_url);
        $update['media_url_thumb'] =$img[0];
        if($do_type == 1){
            $update['media_time'] = date('Y-m-d H:i:s');
            $update['is_publish'] = 1;
        }
    
        $res = Db::table('up_go_school')->where('media_id', $media_id)->update($update);
        if($res){
            return json(['status' => 200, 'msg' => '操作成功']);
        }else{
            return json(['status' => 0, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 草稿箱自训教官操作
     * @return \think\response\Json
     * media_id       ID
     * do_type        操作类型   1 发布   2 保存
     * is_show_user   是否匿名   1 不匿名   2 匿名
     * title          标题
     * content        内容
     * img            图片
     */
    public function doSelf(){
        $media_id = input('media_id');
        $do_type = input('do_type'); // 1 发布   2 保存
        $is_show_user = input('is_show_user'); // 是否匿名  1 不匿名   2 匿名
        $title  = input('title');
        $title  = $this->sensitive($title);
        $content  = input('content');
        $content  = $this->sensitive($content);
        $media_url  = input('img');
        
        $update = [
            'media_title' => $title,
            'media_content' => $content,
            'media_url' => $media_url,
            'media_update_time' => date('Y-m-d H:i:s'),
            'is_show_user' => $is_show_user
        ];
        $img = explode(',',$media_url);
        $update['media_url_thumb'] =$img[0];
        if($do_type == 1){
            $update['media_time'] = date('Y-m-d H:i:s');
            $update['is_publish'] = 1;
        }
        
        $res = Db::table('up_instructor')->where('media_id', $media_id)->update($update);
        if($res){
            return json(['status' => 200, 'msg' => '操作成功']);
        }else{
            return json(['status' => 0, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 草稿箱悬赏问答操作
     * @return \think\response\Json
     * answer_id          ID
     * do_type            操作类型    1 发布   2 保存
     * is_show_user       是否匿名    1 不匿名   2 匿名
     * title              标题
     * answer_describe    描述
     * img                图片
     * video              视频
     */
    public function doAnswer(){
        $answer_id = input('answer_id');
        $do_type = input('do_type'); // 1 发布   2 保存
        $is_show_user = input('is_show_user'); // 是否匿名  1 不匿名   2 匿名
        $title = input('title');
        $title = $this->sensitive($title);
        $answer_describe = input('answer_describe');
        $answer_describe = $this->sensitive($answer_describe);
        $img = input('img');
        $video = input('video');
        
        $update = [
            'answer_title' => $title,
            'answer_describe' => $answer_describe,
            'answer_img' => $img,
            'answer_video' => $video,
            'answer_update_time' => date('Y-m-d H:i:s'),
            'is_show_user' => $is_show_user
        ];
        if($do_type == 1){
            $update['answer_time'] = date('Y-m-d H:i:s');
            $update['answer_money'] = input('answer_money');
            $update['is_publish'] = 1;
        }
        
        $res = Db::table('up_answer')->where('answer_id', $answer_id)->update($update);
        if($res){
            return json(['status' => 200, 'msg' => '操作成功']);
        }else{
            return json(['status' => 0, 'msg' => '操作失败']);
        }
    }
    
    //*************************  草稿箱操作 end **********************//
    
    /**
     * 删除我的发布------发布&草稿箱
     * @return \think\response\Json
     * publish_type    发布的类型    1 资讯   2 老兵自主问答论坛   3 老兵政策解读与案例分享论坛
     *                              4 自媒体论坛  5 军婚军恋   6 考研升学论坛   7 自训教官论坛
     *                              8 悬赏问答   9 短视频
     * subject_id      删除的对象的ID
     */
    public function delMyPublish(){
        $publish_type = input('publish_type');
        $subject_id = input('subject_id');
        
        if($publish_type == 1){ // 删除资讯
            $table = 'up_information';
            $where['information_id'] = $subject_id;
        }elseif($publish_type == 2){ // 删除老兵自主问答论坛
            $table = 'up_old_forum';
            $where['old_forum_id'] = $subject_id;
        }elseif($publish_type == 3){ // 删除老兵政策解读与案例分享论坛
            $table = 'up_share';
            $where['share_id'] = $subject_id;
        }elseif($publish_type == 4){ // 删除自媒体论坛
            $table = 'up_media';
            $where['media_id'] = $subject_id;
        }elseif($publish_type == 5){ // 删除军婚军恋
            $table = 'up_love_post';
            $where['post_id'] = $subject_id;
        }elseif($publish_type == 6){ // 删除考研升学论坛
            $table = 'up_go_school';
            $where['media_id'] = $subject_id;
        }elseif($publish_type == 7){ // 删除自训教官论坛
            $table = 'up_instructor';
            $where['media_id'] = $subject_id;
        }elseif($publish_type == 8){ // 删除悬赏问答
            $table = 'up_answer';
            $where['answer_id'] = $subject_id;
        }else{ // 删除短视频
            $table = 'up_video';
            $where['video_id'] = $subject_id;
        }
        
        $res = Db::table($table)->where($where)->delete();
        if($res){
            return json(['status' => 200, 'msg' => '删除成功']);
        }else{
            return json(['status' => 0, 'msg' => '删除失败']);
        }
    }
    
    /**
     * 我的关注
     * @return \think\response\Json
     * att_type  关注的类型   1 用户  2 社团  3 视频
     * page      页码
     */
    public function myAttention(){
        $attention_type = input('att_type'); // 关注的类型  1 用户  2 社团  3 视频
        
        if($attention_type == 1){ // 用户
            $list = Db::table('up_like')->alias('ul')
                ->join('up_u_user uuu', 'ul.like_user_id = uuu.user_id', 'left')
                ->field('uuu.user_id, uuu.user_username, uuu.user_image')
                ->where('ul.user_id', $this->user_id)
//                ->where('uuu.user_status', 1)
                ->order('like_time desc')
                ->page($this->page, 10)
                ->select();
        }elseif($attention_type == 2){ //社团
            $list = Db::table('up_attention_assn')
                ->join('up_assn', 'att_assn_id = assn_id', 'left')
                ->join('up_school', 'sc_id = assn_school', 'left')
                ->field('assn_id, assn_name, assn_image, sc_name, assn_school_qu, assn_address')
                ->where('att_user_id', $this->user_id)
                ->where('assn_status', 1)
                ->order('att_time desc')
                ->page($this->page, 10)
                ->select();
        }else{ // 视频
            $list = Db::table('up_attention_video')
                ->join('up_video', 'video_id = attention_video_id', 'left')
                ->join('up_u_user', 'user_id = video_user_id', 'left')
                ->field('user_image, user_username, video_url, video_id, video_user_id')
                ->where('attention_user_id', $this->user_id)
                ->where('video_status', 2)
                ->order('attention_time desc')
                ->page($this->page, 10)
                ->select();
        }
        if($list){
            return json(['status' => 200, 'msg' => $list]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 我的社团&群聊
     * @return \think\response\Json
     * show_type   类型  1 社团   2 群里
     * page        页码
     */
    public function myAssnGroup(){
        $show_type = input('show_type'); // 类型  1 社团   2 群聊
        if($show_type == 1){
            $list = Db::table('up_assn_member')
                ->join('up_assn', 'assn_id = am_assn_id', 'left')
                ->field('assn_name, assn_image, assn_id, assn_school, assn_school_qu, assn_address')
                ->where('am_user_id', $this->user_id)
                ->where('am_status', 2)
                ->where('assn_status', 1)
                ->order('am_time desc')
                ->page($this->page, 10)
                ->select();
        }else{
            $list = Db::table('up_group')
                ->field('g_id, g_name, g_thumb')
                ->where('g_status', 1)
                ->where('g_uids', 'like', '%,' . $this->user_id . ',%')
                ->order('g_time desc')
                ->page($this->page, 10)
                ->select();
        }
        if($list){
            return json(['status' => 200, 'msg' => $list]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 消息列表
     * @return \think\response\Json
     * page  页码
     */
    public function systemNotice(){
        // 推送给我的
        $where['n_user_id'] = ['like', '%,' . $this->user_id . ',%'];
        // 未被删除的
        $where['n_del_user_id'] = ['notlike', '%,' . $this->user_id . ',%'];
        $list = Db::table('up_notice')
            ->field('n_id, n_title, n_content, n_read_user_id, n_send_time, n_send_datetime')
            ->where($where)
            ->order('n_send_datetime desc')
            ->page($this->page, 10)
            ->select();
        if($list){
            foreach($list as $k => $v){
                // 时间
                $list[$k]['time'] = $this->showTime($v['n_send_time']);
                
                // 已读/未读
                $read_user = explode(',', trim($v['n_read_user_id'], ','));
                if(in_array($this->user_id, $read_user)){
                    $list[$k]['is_read'] = 1; // 已读
                }else{
                    $list[$k]['is_read'] = 2; // 未读
                }
            }
            return json(['status' => 200, 'msg' => $list]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 系统消息详情 同时修改已读/未读状态
     * @return \think\response\Json
     * n_id   消息ID
     */
    public function noticeDetail(){
        $n_id = input('n_id');
        $detail = Db::table('up_notice')
            ->field('n_title, n_content, n_read_user_id, n_send_time')
            ->where('n_id', $n_id)
            ->find();
        if($detail){
            // 是否是已读消息
            $is_read = explode(',', trim($detail['n_read_user_id'], ','));
            if(!in_array($this->user_id, $is_read)){ // 不在已读数组中，说明未读，需要加入已读字段
                $read_user = $detail['n_read_user_id'] . $this->user_id . ',';
                Db::table('up_notice')->where('n_id', $n_id)->setField('n_read_user_id', $read_user);
            }
            
            // 时间
            $detail['n_send_time'] = $this->showTime($detail['n_send_time']);
            return json(['status' => 200, 'msg' => $detail]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 清空消息列表
     * @return \think\response\Json
     * del_type  列表类型   1 系统消息    2 社团消息
     * del_assn  社团列表类型   1 我审核的    2 我发起的
     */
    public function delAll(){
        $del_type = input('del_type');
        $del_assn = input('del_assn');
        if($del_type == 1){ // 系统消息
            $table = 'up_notice';
            // 推送给我的
            $where['n_user_id'] = ['like', '%,' . $this->user_id . ',%'];
            // 未被删除的
            $where['n_del_user_id'] = ['notlike', '%,' . $this->user_id . ',%'];
            $n_ids = Db::table($table)
                ->where($where)
                ->column('n_id');
        } else{ // 社团消息
            $table = 'up_notice_assn';
            if($del_assn == 1){
                $n_ids = Db::table($table)
                    ->where('n_del_user_id', 'notlike', '%,' . $this->user_id . ',%')
                    ->where(function ($query){
                        $query->where('n_audit_user_id', $this->user_id)
                            ->whereOr('n_assn_manage', 'like', '%,' . $this->user_id . ',%');
                    })
                    ->column('n_id');
            }else{
                $n_ids = Db::table($table)
                    ->where('n_apply_user_id', $this->user_id)
                    ->where('n_audit_status', 'NEQ', 1) // 只展示审核通过和拒绝的
                    ->where('n_del_user_id', 'notlike', '%,' . $this->user_id . ',%')
                    ->column('n_id');
            }
        }
        
        $column = Db::table($table)->where('n_id', 'IN', $n_ids)->column('n_id, n_del_user_id');
        Db::startTrans();
        try{
            foreach($column as $k => $v){
                $del = $v . $this->user_id . ',';
                Db::table($table)->where('n_id', $k)->setField('n_del_user_id', $del);
            }
            Db::commit();
            $res = 1;
        }catch(\Exception $e){
            Db::rollback();
            $res = 2;
        }
        
        if($res == 1){
            return json(['status' => 200, 'msg' => '清空成功']);
        }else{
            return json(['status' => 0, 'msg' => '清空失败']);
        }
    }
    
    /**
     * 我审核的社团列表
     * @return \think\response\Json
     * page  页码
     */
    public function myAuditNotice(){
        // 我的社团
        $myAudit = Db::table('up_notice_assn')
            ->join('up_u_user', 'user_id = n_apply_user_id', 'left')
            ->join('up_assn', 'assn_id = n_assn_id', 'left')
            ->field('n_id, assn_name, user_username, user_image, n_audit_status, n_auth, assn_type')
            ->where('n_del_user_id', 'notlike', '%,' . $this->user_id . ',%')
            ->where(function ($query){
                $query->where('n_audit_user_id', $this->user_id)
                    ->whereOr('n_assn_manage', 'like', '%,' . $this->user_id . ',%');
            })
            ->page($this->page, 10)
            ->order('n_audit_status asc, n_apply_time desc')
            ->select();
        if($myAudit){
            return json(['status' => 200, 'msg' => $myAudit]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 审核社团成员
     * @return \think\response\Json
     * n_id   社团消息ID
     * audit_type   审核类型    2 同意   3 拒绝
     */
    public function auditAssn(){
        $n_id = input('n_id');
        $audit_type  = input('audit_type');
        $info = Db::table('up_notice_assn')
            ->field('n_assn_id, n_apply_user_id, n_auth')
            ->where('n_id', $n_id)
            ->find();
        // 社团信息
        $assn_info = Db::table('up_assn')
            ->where('assn_id', $info['n_assn_id'])
            ->field('assn_type, assn_school')
            ->find();
    
        Db::startTrans();
        try{
            // 更新社团消息表
            $update['n_audit_status'] = $audit_type;
            $update['n_audit_user_id'] = $this->user_id;
            $update['n_audit_time'] = date('Y-m-d H:i:s');
            Db::table('up_notice_assn')->where('n_id', $n_id)->update($update);
            
            $date['am_status'] = $audit_type; // 更新社团成员表状态
            $staff_update['staff_status'] = $audit_type; // 更新社团/成员申请表状态
            // 同意
            if($audit_type == 2){
                // 成员申请，则社团人数加一
                if($info['n_auth'] == 1){
                    Db::table('up_assn')->where('assn_id', $info['n_assn_id'])->setInc('assn_number');
                }

                // 如果审核的是管理员申请，则需讲社团成员表的成员角色换成管理员
                if($info['n_auth'] == 2){
                    $date['am_user_type'] = 2;
                }
    
                // 如果是军事类的社团，则需要生成成员代码
                if($assn_info['assn_type'] == 1){
                    // 学校代码
                    $school_code = Db::table('up_school')
                        ->where('sc_id', $assn_info['assn_school'])
                        ->value('sc_code');
    
                    // 年+月
                    $date_date = date('Ym');
                    $date_str = substr($date_date, 2, 4);
    
                    // 成员序号
                    $code = Db::table('up_about')->where('about_id', 1)->value('about_content');
                    $new_code = trim($code, ',');
                    $staff_member_code = $school_code . $date_str . $new_code . 'JY';
                    $staff_update['staff_member_code'] = $staff_member_code;
    
                    // 更新教员序号
                    $update_code = $new_code + 1;
                    $zero = '';
                    $leng = strlen($update_code);
                    if($leng < 6){
                        for($i = $leng; $i<6; $i++){
                            $zero .= '0';
                        }
                    }
                    $about_code = ',' . $zero . $update_code . ',';
                    Db::table('up_about')->where('about_id', 1)->update(['about_content' => $about_code]);
                }
            }
            // 更新社团成员表
            Db::table('up_assn_member')
                ->where('am_assn_id', $info['n_assn_id'])
                ->where('am_user_id', $info['n_apply_user_id'])
                ->update($date);
            
            // 更新成员信息
            Db::table('up_staff')
                ->where('staff_user_id', $info['n_apply_user_id'])
                ->where('staff_assn_id', $info['n_assn_id'])
                ->update($staff_update);
            
            Db::commit();
            $res = 1;
        }catch(\Exception $e){
            Db::rollback();
            $res = 2;
        }
        
        if($res == 1){
            $list = [];//需要推送的用户数组
            $val = (string)$info['n_apply_user_id'];
            array_push($list, $val);
            if($audit_type == 2){
                $str = '您提交的申请已经审核通过';
            }else{
                $str = '您提交的申请审核失败';
            }
            try{
                $this->Jpush(1, $list, $str, ['send_type' => 15]);
            }catch(\Exception $e){
            }
            return json(['status' => 200, 'msg' => '操作成功']);
        }else{
            return json(['status' => 0, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 审核时，成员信息回显
     * @return \think\response\Json
     * n_id      消息ID
     */
    public function showAudit(){
        $n_id = input('n_id');
        $assn_info = Db::table('up_notice_assn')
            ->where('n_id', $n_id)
            ->field('n_assn_id, n_apply_user_id')
            ->find();
        $assn_type = Db::table('up_assn')->where('assn_id', $assn_info['n_assn_id'])->value('assn_type');
        if($assn_type == 1){
            $staff = Db::table('up_staff')
                ->join('up_school', 'sc_id = staff_school_id', 'left')
                ->join('up_politics', 'politics_id = staff_politics')
                ->where('staff_assn_id', $assn_info['n_assn_id'])
                ->where('staff_user_id', $assn_info['n_apply_user_id'])
                ->field('sc_name, staff_assn_name, staff_name, staff_gender, staff_birthday, 
            staff_user_card, politics_name, staff_assn_duty, staff_faculty, staff_in_assn_time, 
            staff_old_troops, staff_specilay, staff_phone, staff_sign, staff_sign_time, staff_grade')
                ->find();
        }else{
            $staff = Db::table('up_staff')
                ->join('up_school', 'sc_id = staff_school_id', 'left')
                ->where('staff_assn_id', $assn_info['n_assn_id'])
                ->where('staff_user_id', $assn_info['n_apply_user_id'])
                ->field('sc_name, staff_name, staff_gender, staff_birthday, staff_faculty,
                staff_specilay, staff_phone, staff_grade')
                ->find();
        }
        
        if($staff){
            return json(['status' => 200, 'msg' => $staff]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
        
    }
    
    /**
     * 我发起的社团申请列表
     * @return \think\response\Json
     */
    public function myApply(){
        $list = Db::table('up_notice_assn')
            ->join('up_u_user', 'n_audit_user_id = user_id', 'left')
            ->join('up_assn', 'assn_id = n_assn_id', 'left')
            ->where('n_apply_user_id', $this->user_id)
            ->where('n_audit_status', 'NEQ', 1) // 只展示审核通过和拒绝的
            ->where('n_del_user_id', 'notlike', '%,' . $this->user_id . ',%')
            ->field('n_id, user_username, user_image, assn_name, n_audit_status')
            ->page($this->page, 10)
            ->order('n_audit_time desc')
            ->select();
        if($list){
            return json(['status' => 200, 'msg' => $list]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 我的钱包
     * @return \think\response\Json
     * page  页码
     */
    public function myWallet(){
        // 我的余额
        $balance = Db::table('up_u_user')
            ->field('user_balance')
            ->where('user_id', $this->user_id)
            ->find();
        // 提现列表
        $getMoney = Db::table('up_order')
            ->field('order_id, order_money, order_pay_time, order_type, order_cate')
            ->where('order_user_id', $this->user_id)
            ->where('order_cate', 'NEQ', 1)
            ->where('order_status', 2)
            ->page($this->page, 10)
            ->order('order_pay_time desc')
            ->select();
        if($getMoney){
            // 时间格式
            foreach($getMoney as $k => $v){
                $time = strtotime($v['order_pay_time']);
                $getMoney[$k]['order_pay_time'] = date('Y-m-d H:i', $time);
            }
            $balance['getMoney'] = $getMoney;
        }else{
            $balance['getMoney'] = [];
        }
        return json(['status' => 200, 'msg' => $balance]);
    }
    
    /**
     * 对我的评论
     * @return \think\response\Json
     */
    public function myCommentSubject(){
        $comment = Db::table('up_comment')->alias('uc')
            ->join('up_u_user uuu', 'uuu.user_id = uc.user_id', 'left')
            ->field('uuu.user_username, uuu.user_image, uc.comment_id, uc.comment, uc.time, uc.type, uc.f_id, 
            uc.is_readed')
            ->where('f_user_id', $this->user_id)
            ->page($this->page, 10)
            ->order('uc.time desc')
            ->select();
        if($comment){
            return json(['status' => 200, 'msg' => $comment]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 对我评论的回复
     * @return \think\response\Json
     */
    public function myCommentReply(){
        $reply = Db::table('up_comment_reply')
            ->alias('ucr')
            ->join('up_comment uc', 'uc.comment_id = ucr.f_id', 'left')
            ->join('up_u_user uuu', 'uuu.user_id = ucr.user_id', 'left')
            ->field('ucr.comment_reply_id, ucr.comment_reply_content, ucr.comment_time, uc.comment, 
            uc.type, uuu.user_username, uuu.user_image, uc.f_id, ucr.is_readed')
            ->where('by_user_id', $this->user_id)
            ->page($this->page, 10)
            ->order('comment_time desc')
            ->select();
        if($reply){
            return json(['status' => 200, 'msg' => $reply]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 对我的点赞
     * @return \think\response\Json
     */
    public function myZan(){
        $zan = Db::table('up_comment_give')
            ->join('up_u_user', 'user_id = give_user_id', 'left')
            ->field('user_username, user_image, give_time, give_type, give_id, give_user_id, 
            give_f_f_id, is_readed')
            ->where('give_by_user_id', $this->user_id)
            ->page($this->page, 10)
            ->order('give_time desc')
            ->select();
        if($zan){
            return json(['status' => 200, 'msg' => $zan]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 兴趣标签
     * @return \think\response\Json
     */
    public function interest(){
        $interest = Db::table('up_interest')->field('interest_id, interest_word')->select();
        if($interest){
            return json(['status' => 200, 'msg' => $interest]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 选择兴趣标签
     * @return \think\response\Json
     * interest_ids    兴趣标签ID
     */
    public function chooseInterest(){
        $update['user_interest'] = input('interest_ids') ? input('interest_ids') : null;
        $update['user_is_interest'] = 2;
        $res = Db::table('up_u_user')->where('user_id', $this->user_id)->update($update);
        if($res){
            $user_info = Db::table('up_u_user')->where('user_id', $this->user_id)->find();
            return json(['status' => 200, 'msg' => $user_info]);
        }else{
            return json(['status' => 0, 'msg' => '']);
        }
    }
    
    //*************************  我的收藏 start **********************//
    
    /**
     * 我的收藏
     * @return \think\response\Json
     * page   页码
     * collention_type  发布的类型   1 资讯   3 老兵自主问答论坛   4 老兵政策解读与案例分享论坛
     *                              2 自媒体论坛  5 军婚军恋   6 考研升学论坛   7 自训教官论坛
     *                              8 悬赏问答
     * son_type         当收藏类型为3老兵自主问答论坛时，传此值   1 政策解读   2 答疑解惑
     */
    public function myCollection(){
        $collention_type = input('collention_type');
        if($collention_type == 1){ // 资讯
            $list = Db::table('up_collection')
                ->join('up_information', 'collection_f_id = information_id', 'left')
                ->join('up_u_user', 'user_id = information_user_id', 'left')
                ->field('information_id, information_title, information_thumb, information_content, information_week, 
                user_username, is_admin, is_show_user')
                ->where('collection_user_id', $this->user_id)
                ->where('collection_type', 1)
                ->order('collection_id desc')
                ->page($this->page, 10)
                ->select();
        }elseif($collention_type == 3){ // 老兵自主问答论坛
            $son_type = input('son_type'); // 1 政策解读  2 答疑解惑
            $list = Db::table('up_collection')
                ->join('up_old_forum', 'collection_f_id = old_forum_id', 'left')
                ->field('old_forum_id, old_forum_title, old_forum_time, is_show_user')
                ->where('collection_user_id', $this->user_id)
                ->where('old_forum_type', $son_type)
                ->where('collection_type', 3)
                ->order('collection_id desc')
                ->page($this->page, 10)
                ->select();
            if($list){
                foreach($list as $k => $v){
                    $count = Db::table('up_old_answer')->where('f_id', $v['old_forum_id'])->count();
                    $answer = Db::table('up_old_answer')
                        ->field('old_answer_content, old_answer_video, old_answer_img, is_show_user')
                        ->where('f_id', $v['old_forum_id'])
                        ->order('old_answer_time desc')
                        ->find();
                    $list[$k]['answer_num'] = $count;
                    $list[$k]['answer'] = $answer;
                }
            }
        }elseif($collention_type == 4){ // 老兵政策解读与案例分享论坛
            $list = Db::table('up_collection')
                ->join('up_share', 'collection_f_id = share_id', 'left')
                ->join('up_u_user', 'user_id = share_user_id', 'left')
                ->field('share_id, share_title, share_content, share_time, share_url, user_username, 
                is_show_user')
                ->where('collection_user_id', $this->user_id)
                ->where('collection_type', 4)
                ->order('collection_id desc')
                ->page($this->page, 10)
                ->select();
        }elseif($collention_type == 2){ // 自媒体论坛
            $list = Db::table('up_collection')
                ->join('up_media', 'collection_f_id = media_id', 'left')
                ->join('up_u_user', 'user_id = media_user_id', 'left')
                ->field('media_id, media_title, media_content, media_time, media_url, media_url_thumb, 
                user_username, is_admin, is_show_user')
                ->where('collection_user_id', $this->user_id)
                ->where('collection_type', 2)
                ->order('collection_id desc')
                ->page($this->page, 10)
                ->select();
        }elseif($collention_type == 5){ // 军婚军恋
            $list = Db::table('up_collection')
                ->join('up_love_post', 'collection_f_id = post_id', 'left')
                ->join('up_u_user', 'user_id = post_user_id', 'left')
                ->field('post_id, post_content, post_img, post_create_time, user_username, 
                user_image, is_show_user')
                ->where('collection_user_id', $this->user_id)
                ->where('post_status', 1)
                ->where('collection_type', 5)
                ->order('collection_id desc')
                ->page($this->page, 10)
                ->select();
            if($list){
                foreach($list as $k => $v){
                    $count = Db::table('up_comment')
                        ->where('type', 3)
                        ->where('f_id', $v['post_id'])
                        ->count();
                    $list[$k]['count'] = $count;
                }
            }
        }elseif($collention_type == 6){ // 考研升学论坛
            $list = Db::table('up_collection')
                ->join('up_go_school', 'collection_f_id = media_id', 'left')
                ->join('up_u_user', 'user_id = media_user_id', 'left')
                ->field('media_id, media_title, media_content, media_time, media_url, media_url_thumb, 
                user_username, is_show_user')
                ->where('collection_user_id', $this->user_id)
                ->where('collection_type', 6)
                ->order('collection_id desc')
                ->page($this->page, 10)
                ->select();
        }elseif($collention_type == 7){ // 自训教官论坛
            $list = Db::table('up_collection')
                ->join('up_instructor', 'collection_f_id = media_id', 'left')
                ->join('up_u_user', 'user_id = media_user_id', 'left')
                ->field('media_id, media_title, media_content, media_time, media_url, media_url_thumb, 
                user_username, is_show_user')
                ->where('collection_user_id', $this->user_id)
                ->where('collection_type', 7)
                ->order('collection_id desc')
                ->page($this->page, 10)
                ->select();
        }else{ // 悬赏问答
            $list = Db::table('up_collection')
                ->join('up_answer', 'collection_f_id = answer_id', 'left')
                ->field('answer_id, answer_title, answer_time, is_show_user, collection_f_id')
                ->where('collection_user_id', $this->user_id)
                ->where('collection_type', 8)
                ->order('collection_id desc')
                ->page($this->page, 10)
                ->select();
            if($list){
                foreach($list as $k => $v){
                    $count = Db::table('up_answer_reply')->where('f_id', $v['collection_f_id'])->count();
                    $answer = Db::table('up_answer_reply')
                        ->join('up_u_user', 'reply_answer_user_id = user_id', 'left')
                        ->field('reply_answer_video, is_show_user, user_username, reply_answer_content')
                        ->where('f_id', $v['collection_f_id'])
                        ->order('reply_answer_time desc')
                        ->find();
                    $list[$k]['answer_num'] = $count;
                    $list[$k]['answer'] = $answer;
                }
            }
        }
        
        return json(['status' => 200, 'msg' => $list]);
    }
    
    //*************************  我的收藏 end **********************//
    
    /**
     * 用户认证通过类型
     * @return \think\response\Json
     */
    public function userAtt(){
        // 如果看的是别人的
        $other_user_id = input('other_user_id');
        if(isset($other_user_id) && $other_user_id != ''){
            $this->user_id = $other_user_id;
        }
        $role_type = Db::table('up_user_role')
            ->where('role_user_id', $this->user_id)
            ->where('role_audit_status', 2)
            ->column('role_user_type');
        if($role_type){
            return json(['status' => 200, 'msg' => $role_type]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 根据ID获取短视频地址
     * @return \think\response\Json
     * id
     */
    public function getVidelUrl(){
        $video_id = input('id');
        $url = Db::table('up_video')
            ->where('video_id', $video_id)
            ->field('video_url')
            ->find();
        return json(['status' => 200, 'msg' => $url]);
    }
    
    /**
     * 返回省ID 用于定位
     * @return \think\response\Json
     */
    public function getShengId(){
        $sheng = input('sheng');
        $id = Db::table('up_area')->where('district', $sheng)->value('district_id');
        if($id){
            return json(['status' => 200, 'msg' => $id]);
        }else{
            return json(['status' => 200, 'msg' => '定位失败']);
        }
    }
    
    /**
     * 根据省ID，获取市ID
     * @return \think\response\Json
     */
    public function getShiId(){
        $sheng = input('sheng');
        $info = Db::table('up_area')
            ->where('pid', $sheng)
            ->field('district_id, district')
            ->select();
        if($info){
            return json(['status' => 200, 'msg' => $info]);
        }else{
            return json(['status' => 200, 'msg' => '获取城市失败']);
        }
    }
    
    /**
     * 退出
     * @return \think\response\Json
     */
    public function loginOut(){
        $res = Db::table('up_u_user')->where('user_id', $this->user_id)->setField('user_online', 2);
        if($res){
            return json(['status' => 200, 'msg' => '退出成功']);
        }else{
            return json(['status' => 0, 'msg' => '退出失败']);
        }
    }
    
    //=============================  支付宝提现   start  ======================//
    /**
     * 支付宝提现
     * @return \think\response\Json
     * amount      提现金额
     * real_name   真实姓名
     * account     支付宝账号
     */
    public function aliTiXian(){
        header("Content-type: text/html; charset=utf-8");
        $amount = input('amount'); // 提现金额
        $real_name = input('real_name'); // 真实姓名
        $account = input('account'); // 支付宝账号
        $order_num = date('YmdHis') . rand(0, 999999); // 订单编号
        $user_balance = Db::table('up_u_user')->where('user_id', $this->user_id)->value('user_balance');
        if($amount > $user_balance) return json(['status' => 0, 'msg' => '账户余额不足']);
        // 生成订单
        $insert = [
            'order_cate' => 2,
            'order_type' => 1,
            'order_num' => $order_num,
            'order_money' => $amount,
            'order_status' => 1,
            'order_ali_id' => $account,
            'order_real_name' => $real_name,
            'order_user_id' => $this->user_id,
            'order_time' => $this->create_time
        ];
        $order_id = Db::table('up_order')->insertGetId($insert);
        
        if($order_id){
            // 引入文件
//            require_once(EXTEND_PATH.'alipay/AopSdk.php');
            Loader::import('alipay.aop.AopClient',EXTEND_PATH,'.php');
            Loader::import('alipay.aop.request.AlipayFundTransToaccountTransferRequest',EXTEND_PATH,'.php');
//            Loader::import('alipay.aop.SignData',EXTEND_PATH,'.php');// 在AopClient类中已经引用，此处无序重复引用
            $aop = new \AopClient();
            // 支付宝网关，固定不变
            $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
            // appId 应用的ID
            $aop->appId = '2019080566158002';
            // 私钥，工具生成
            $aop->rsaPrivateKey = 'MIIEpAIBAAKCAQEAwZp4bJH3Jovh59yodKEm+QRmuA+CLOTlEU/XmtVhDN0/U4AZBl54I+9zZifVmKHfnUBjdE7MbMLPGwRiklPM2ByPS/0Nnz3YZoSz0dpZg46IXCqAIThs9WI+OB/tVeZAFThRbHb2c7yEgK8fOwmX1iAwHo2yNQcT/Z+9OPH2wp6zQ5bAAcIMBK7Ewm5ZM+sddeHDiYVulX5MwEUqDk+jkK0L2COhpEh2peb97sOa4lAI0r1egwELRspMNZfqZorQPelL0IjRmOPRh1AhbCtw8lV/NvY1smGmuxiRR1LlAr3kiO4DBgbb6D+zM2JNSChawO7X0Avxm8u5f+aVOrCUpQIDAQABAoIBAAlWgwJxk+MnEhFV4kYl07RlEvNDxDqYG7hXCoYsTo8JSNmlLw/QlKjfDsjZmQLQo/F4vpNIjbGdP9IExyBZrGKsFflLTlHk8MAZHHc9ud2PjWIspptzlkXLpEaeu5rODT84xSyfHEn+yMFQMQhu8QTh7pA6s2K9Yah1APJzMTy3x0ZGwJZZwoVXa/WElNE7GUvDbcIIgPWFb08znR4FNlXMO9ZOOQ4gYUGvsXd6u9KmwCTKsqOnrwT7i4YVAW3xZeH5+5sb0JVXRKrtCZVs6jc72e050CmPrla9HYUtVc7yFG4I5M7DDJlUrr0XdkVyUdnNc7XHPZt3vS0rquCefmECgYEA9hVqyO/osotrwzdViHMkJJimOPrtj6xsHJOiHxII++12DqL6kB6HxhJjnRM/adMNHutyVfOOjoE07i7vMEMsEXGa5clnPwjhhqP/lHaX8ybeRy2JX/DMEfAlfsqsVKcA7iE0lqeAfpj3yryCqOk0zbb2GFzDbktaYWPe8sVcc2kCgYEAyWernJlP7MfnoNmHlBvk+cQmHlIn3cZLs+ODBvc6ZaHfeMAMXqzA0hl4RU7TX1pe86iz9S0FlhEZQRAXedawea+RFa5qkReX3/gm9odktb6qENU1psDePBP2iJ+RWLKQtpP/fWeGqMJCee9ycTHLMf/nnjocQ0bwcQ+SCZzR+90CgYEA9ALOrUq/CfQXui5vQOszZpp7ELs4vyNw3HFD6909TVnsm5zeKfQsG6r2XbXNRokBVKyQ5kupCwNx0dB2WvvwgaeNudcY6rdKsfCCqNtj1rau6BNuSdUC9bKT64LamOI0mOwSMmULk/zokH6WbRk5w9ZtdkDdhMtxZmrakw5CmykCgYEAyQ7FMr+aGjY19U0zG5f9LZmys/Iv+iVKzXoCA6IqmerOvCx8LMcodpUWi5n1SOtefr+bZtZbDURkgZ8e0HKSGeg6XfqQR+fVpbCEtPbUgtqjy8oMlTtUn4UOR7WD05fu/1UfaIFA3JeQ5Uk0ZevffTqKblp0fHUE8tkoYJA8z8ECgYAtLZSkSDepPhwqcENISknkUm8QOS0PwssRqt7GNO/TUaw3UR0M1cnAne4VyyIyi3VLu7YpXn5/zWNNI8ISYQUUHBE4mymfWL7qLPAmVhYL1cqko29n38cm3SgJp1G2On/dfxiTQVi1XdcfnCq8Z8JC7KOr4WGDbrCVhGZnfWErZg==';
            // 支付宝公钥 上传应用公钥后 支付宝生成的支付宝公钥
            $aop->alipayrsaPublicKey ='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqP3RSHJuQcjitVbRqOu7OI5rl7+bqTDbpWgWECwjLpDHvG2YhVuwOpRWZ+Ix4EH5WKIdQv1zGOZstWHkIQD4JyBIASj9vp3R3noSUkab31/Yp4fjJOzdgIO7Ldh4mwGhxW4oXLRg3GajR0FlFfvBMglkozcbe2MRxA6KAWauouTjJPTME4429oCLNMJlckMwxA2DFzbH6pBge/+sLpocJbGDEKngid04gidKs5tJ+Oif2JRTJcHe+qsMQQOLRiWE/YIVHE8QggPljBoVjY/c7ezBBe1ERfiX9rUImFx7mYnAePt/45fuhpdatRS74TdkvicaJ0YCVGxHCc+Ez3zNMQIDAQAB';
            // 版本  固定
            $aop->apiVersion = '1.0';
            // 签名类型  固定
            $aop->signType = 'RSA2';
            // 编码  固定
            $aop->postCharset='UTF-8';
            // 格式 固定
            $aop->format='json';
            $request = new \AlipayFundTransToaccountTransferRequest();
            // 收款方账户类型为（payee_type）：
            // 1.ALIPAY_LOGONID：支付宝登录号，支持邮箱和手机号格式。
            // 2.ALIPAY_USERID：支付宝账号对应的支付宝唯一用户号。以2088开头的16位纯数字组成。
            $request->setBizContent("{" .
                "\"out_biz_no\":\"$order_num\"," .
                "\"payee_type\":\"ALIPAY_LOGONID\"," .
                "\"payee_account\":\"$account\"," .
                "\"amount\":\"$amount\"," .
                "\"payee_real_name\":\"$real_name\"," .
                "}");
            $result = $aop->execute($request);
            $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
            $resultCode = $result->$responseNode->code;
            if(!empty($resultCode) && $resultCode == 10000){
                Db::startTrans();
                try{
                    // 修改状态
                    $update = [
                        'order_pay_time' => $this->create_time,
                        'order_status' => 2,
                    ];
                    Db::table('up_order')->where('order_id', $order_id)->update($update);
                    // 减用户余额
                    Db::table('up_u_user')->where('user_id', $this->user_id)->setDec('user_balance', $amount);
                    Db::commit();
                    return json(['status' => 200, 'msg' => '操作成功']);
                }catch(\Exception $e){
                    Db::rollback();
                    return json(['status' => 0, 'msg' => '操作数据库失败']);
                }
            }else{
                // $result->$responseNode->sub_msg 这个参数 是返回的错误信息
//                throw new Exception($result->$responseNode->sub_msg);
                return json(['status' => 0, 'msg' => $result->$responseNode->sub_msg]);
            }
        }else{
            return json(['status' => 0,' msg' => '网络异常，请稍后重试']);
        }
        
    }
    //=============================  支付宝提现   end  ======================//
    
    //=============================  微信提现   start  ======================//
    /*
     * amount   提现金额
     * real_name   真实姓名
     * account    微信账号
     * openid   用户openid
     */
    public function wxTiXian(){
        header("Content-type: text/html; charset=utf-8");
        $amount = input('amount'); // 提现金额
        $real_name = input('real_name'); // 真实姓名
        $account = input('account'); // 微信账号
        $order_num = date('YmdHis') . rand(0, 999999); // 订单编号
        
        $user_balance = Db::table('up_u_user')->where('user_id', $this->user_id)->value('user_balance');
        if($amount > $user_balance) return json(['status' => 0, 'msg' => '账户余额不足']);
    
        // 生成订单
        $insert = [
            'order_cate' => 2,
            'order_type' => 2,
            'order_num' => $order_num,
            'order_money' => $amount,
            'order_status' => 1,
            'order_wx_id' => $account,
            'order_real_name' => $real_name,
            'order_user_id' => $this->user_id,
            'order_time' => $this->create_time
        ];
        $order_id = Db::table('up_order')->insertGetId($insert);
        if($order_id){
            // 请求地址  固定
            $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
            // 商户平台设置的秘钥
            $key = 'DJIhYFpSXwDEs5sWKmQR0QfwLGYPdjVi';
    
            $data = [];
            // 商户号的appid
            $data['mch_appid'] = 'wx7c737b922313c61a';
            // 商户号
            $data['mchid'] = '1550927841';
            // 随机数
            $data['nonce_str'] = $this->getRandChar(32);
            // 订单号
            $data['partner_trade_no'] = $order_num;
            // 用户的唯一标识
            $data['openid'] = input('openid');
            // 是否校验真实姓名  FORCE_CHECK:强制校验   NO_CHECK:不校验
            $data['check_name'] = 'FORCE_CHECK';
            // 真实姓名
            $data['re_user_name'] = $real_name;
            // 金额
            $data['amount'] = $amount * 100;
            // 备注
            $data['desc'] = '用户提现';
            // ip地址
            $data['spbill_create_ip'] = request()->ip();
            // 签名
            $data['sign'] = $this->makeSign($data, $key);
            // 将数据转换成xml格式
            $xml = $this->toXml($data);
            // 将生成的xml数据进行请求
            $response = $this->httpRequest($url, $xml);
            $rdata = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA);
            $return_code = (string)$rdata->return_code;
            $result_code = (string)$rdata->result_code;
            $return_code = trim(strtoupper($return_code));
            $result_code = trim(strtoupper($result_code));
    
            if ($return_code == 'SUCCESS' && $result_code == 'SUCCESS') {
                Db::startTrans();
                try{
                    // 修改状态
                    $update = [
                        'order_status' => 2,
                        'order_pay_time' => $this->create_time
                    ];
                    Db::table('up_order')->where('order_id', $order_id)->update($update);
                    // 减用户余额
                    Db::table('up_u_user')->where('user_id', $this->user_id)->setDec('user_balance', $amount);
                    Db::commit();
                    return json(['status' => 200, 'msg' => '操作成功']);
                }catch(\Exception $e){
                    Db::rollback();
                    return json(['status' => 0, 'msg' => '操作数据库失败']);
                }
            } else {
                $returnmsg = (string)$rdata->return_msg;
                return json(['status' => 0, 'msg' => $returnmsg]);
            }
        }else{
            return json(['status' => 0, 'msg' => '网络异常，请稍后重试']);
        }
        
    }
    
    /*
     * 发送请求
     * @param  string $url      请求的url地址
     * @param  array  $postData 请求的数据
     */
    public function httpRequest($url, $postData = [])
    {
        $header[] = "Content-type: text/xml";//定义content-type为xml,注意是数组
        // 初始化curl
        $ch = curl_init();
        // 设置请求的url地址
        curl_setopt($ch, CURLOPT_URL, $url);
        // 将curl_exec()获取的信息以字符串返回，而不是直接输出。
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // 发送post请求
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        //curl注意事项，如果发送的请求是https，必须要禁止服务器端校检SSL证书
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
        curl_setopt($ch,CURLOPT_SSLCERT,ROOT_PATH.'/public/apiclient_cert.pem');
        curl_setopt($ch,CURLOPT_SSLCERTTYPE,'pem');
        curl_setopt($ch,CURLOPT_SSLKEY,ROOT_PATH.'/public/apiclient_key.pem');
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        
        // 执行curl
        $result = curl_exec($ch);
        if(curl_errno($ch)){
            print curl_error($ch);
        }
        // 关闭curl
        curl_close($ch);
        
        return $result;
    }
    
    /**
     * 生成签名
     * @return 签名，本函数不覆盖sign成员变量，如要设置签名需要调用SetSign方法赋值
     */
    public function makeSign($data, $key){
        // 去空
        $data=array_filter($data);
        //签名步骤一：按字典序排序参数
        ksort($data);
        $string_a=http_build_query($data);
        $string_a=urldecode($string_a);
        //签名步骤二：在string后加入KEY
        $string_sign_temp=$string_a."&key=".$key;
        //签名步骤三：MD5加密
        $sign = md5($string_sign_temp);
        // 签名步骤四：所有字符转为大写
        $result=strtoupper($sign);
        return $result;
    }
    
    /**
     * 输出xml字符
     * @throws WxPayException
     **/
    public function toXml($data){
        //var_dump($data);
        if(!is_array($data) || count($data) <= 0){
            //throw new WxPayException("数组数据异常！");
        }
        $xml = "<xml>";
        foreach ($data as $key=>$val){
            if (is_numeric($val)){
                $xml.="<".$key.">".$val."</".$key.">";
            }else{
                $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
            }
        }
        $xml.="</xml>";
        return $xml;
    }
    
    /**
     * 将xml转为array
     * @param  string $xml xml字符串
     * @return array       转换得到的数组
     */
    public function toArray($xml){
        //禁止引用外部xml实体
        libxml_disable_entity_loader(true);
        $result= json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        return $result;
    }
    
    /**
     * 获取指定长度的随机字符串
     * @param $length
     * @return null|string
     */
    function getRandChar($length){
        $str = null;
        $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
        $max = strlen($strPol)-1;
        for($i=0;$i<$length;$i++){
            $str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
        }
        return $str;
    }
    //=============================  微信提现   end  ======================//
    
    /**
     * 我的底部----红点
     * @return \think\response\Json
     */
    public function myDown(){
        // 我的社团
        $myAudit = Db::table('up_notice_assn')
            ->where('n_del_user_id', 'notlike', '%,' . $this->user_id . ',%')
            ->where('n_assn_manage', 'like', '%,' . $this->user_id . ',%')
            ->where('n_audit_status', 1)
            ->select();
        // 我的系统消息
        $mySystemNotice = Db::table('up_notice')
            ->where('n_user_id', 'like', '%,' . $this->user_id . ',%')
            ->where('n_del_user_id', 'notlike', '%,' . $this->user_id . ',%')
            ->where('n_read_user_id', 'notlike', '%,' . $this->user_id . ',%')
            ->select();
        // 我的评论点赞---回复
        $reply = Db::table('up_comment_reply')
            ->alias('ucr')
            ->join('up_comment uc', 'uc.comment_id = ucr.f_id', 'left')
            ->join('up_u_user uuu', 'uuu.user_id = ucr.user_id', 'left')
            ->where('by_user_id', $this->user_id)
            ->where('ucr.is_readed', 1)
            ->select();
        // 我的评论点赞---评论
        $comment = Db::table('up_comment')->alias('uc')
            ->join('up_u_user uuu', 'uuu.user_id = uc.user_id', 'left')
            ->where('f_user_id', $this->user_id)
            ->where('uc.is_readed', 1)
            ->select();
        // 我的评论点赞---点赞
        $zan = Db::table('up_comment_give')
            ->join('up_u_user', 'user_id = give_user_id', 'left')
            ->where('give_by_user_id', $this->user_id)
            ->where('is_readed', 1)
            ->select();
        if($myAudit || $mySystemNotice || $reply || $comment || $zan){
            $red = 1;
        }else{
            $red = 2;
        }
        return json(['status' => 200, 'msg' => $red]);
    }
    
    /**
     * 消息显示红点
     * @return \think\response\Json
     */
    public function redPoint(){
        // 我的社团（我的审核）
        $myAudit = Db::table('up_notice_assn')
            ->where('n_del_user_id', 'notlike', '%,' . $this->user_id . ',%')
            ->where('n_assn_manage', 'like', '%,' . $this->user_id . ',%')
            ->where('n_audit_status', 1)
            ->select();
        // 我的系统消息
        $mySystemNotice = Db::table('up_notice')
            ->where('n_user_id', 'like', '%,' . $this->user_id . ',%')
            ->where('n_del_user_id', 'notlike', '%,' . $this->user_id . ',%')
            ->where('n_read_user_id', 'notlike', '%,' . $this->user_id . ',%')
            ->select();
        if($myAudit || $mySystemNotice){
            $red = 1;
        }else{
            $red = 2;
        }
        return json(['status' => 200, 'msg' => $red]);
    }
    
    /**
     * 我的社团信息（审核）---红点
     * @return \think\response\Json
     */
    public function redPointAssn(){
        $myAudit = Db::table('up_notice_assn')
            ->where('n_del_user_id', 'notlike', '%,' . $this->user_id . ',%')
            ->where('n_assn_manage', 'like', '%,' . $this->user_id . ',%')
            ->where('n_audit_status', 1)
            ->select();
        if($myAudit){
            $red = 1;
        }else{
            $red = 2;
        }
        return json(['status' => 200, 'msg' => $red]);
    }
    
    /**
     * 我的系统信息---红点
     * @return \think\response\Json
     */
    public function redPointSystem(){
        $mySystemNotice = Db::table('up_notice')
            ->where('n_user_id', 'like', '%,' . $this->user_id . ',%')
            ->where('n_del_user_id', 'notlike', '%,' . $this->user_id . ',%')
            ->where('n_read_user_id', 'notlike', '%,' . $this->user_id . ',%')
            ->select();
        if($mySystemNotice){
            $red = 1;
        }else{
            $red = 2;
        }
        return json(['status' => 200, 'msg' => $red]);
    }
    
    /**
     * 我的评论点赞----红点
     * @return \think\response\Json
     */
    public function myPl(){
        // 我的评论点赞---回复
        $reply = Db::table('up_comment_reply')
            ->alias('ucr')
            ->join('up_comment uc', 'uc.comment_id = ucr.f_id', 'left')
            ->join('up_u_user uuu', 'uuu.user_id = ucr.user_id', 'left')
            ->where('by_user_id', $this->user_id)
            ->where('ucr.is_readed', 1)
            ->select();
        // 我的评论点赞---评论
        $comment = Db::table('up_comment')->alias('uc')
            ->join('up_u_user uuu', 'uuu.user_id = uc.user_id', 'left')
            ->where('f_user_id', $this->user_id)
            ->where('uc.is_readed', 1)
            ->select();
        // 我的评论点赞---点赞
        $zan = Db::table('up_comment_give')
            ->join('up_u_user', 'user_id = give_user_id', 'left')
            ->where('give_by_user_id', $this->user_id)
            ->where('is_readed', 1)
            ->select();
        if($reply || $comment || $zan){
            $red = 1;
        }else{
            $red = 2;
        }
        return json(['status' => 200, 'msg' => $red]);
    }
    
    /**
     * 回复-----红点
     * @return \think\response\Json
     */
    public function redPointReply(){
        $reply = Db::table('up_comment_reply')
            ->alias('ucr')
            ->join('up_comment uc', 'uc.comment_id = ucr.f_id', 'left')
            ->join('up_u_user uuu', 'uuu.user_id = ucr.user_id', 'left')
            ->where('by_user_id', $this->user_id)
            ->where('ucr.is_readed', 1)
            ->select();
        if($reply){
            $red = 1;
        }else{
            $red = 2;
        }
        return json(['status' => 200, 'msg' => $red]);
    }
    
    /**
     * 评论----红点
     * @return \think\response\Json
     */
    public function redPointSubject(){
        $comment = Db::table('up_comment')->alias('uc')
            ->join('up_u_user uuu', 'uuu.user_id = uc.user_id', 'left')
            ->where('f_user_id', $this->user_id)
            ->where('uc.is_readed', 1)
            ->select();
        if($comment){
            $red = 1;
        }else{
            $red = 2;
        }
        return json(['status' => 200, 'msg' => $red]);
    }
    
    /**
     * 点赞-----红点
     * @return \think\response\Json
     */
    public function redPointZan(){
        $zan = Db::table('up_comment_give')
            ->join('up_u_user', 'user_id = give_user_id', 'left')
            ->where('give_by_user_id', $this->user_id)
            ->where('is_readed', 1)
            ->select();
        if($zan){
            $red = 1;
        }else{
            $red = 2;
        }
        return json(['status' => 200, 'msg' => $red]);
    }
    
    /**
     * 匹配幸运数字
     * @return \think\response\Json
     * luck_num    输入的幸运数字
     */
    public function writeLuck(){
        $luck_num = input('luck_num');
        $is_have = Db::table('up_luck')
            ->where('luck_user_id', $this->user_id)
            ->find();
        // 1.先更新或插入
        if($is_have){
            $update = [
                'luck_num' => ',' . $luck_num,
                'luck_time' => date('Y-m-d H:i:s')
            ];
            $res = Db::table('up_luck')->where('luck_user_id', $this->user_id)->update($update);
        }else{
            $insert = [
                'luck_num' => ',' . $luck_num,
                'luck_user_id' => $this->user_id,
                'luck_time' => date('Y-m-d H:i:s')
            ];
            $res = Db::table('up_luck')->insert($insert);
        }
        
        // 2.如果插入/更新成功，则匹配
        if($res){
            $result = Db::table('up_luck')
                ->join('up_u_user', 'user_id = luck_user_id', 'left')
                ->field('user_id, user_username, user_image')
                ->where('luck_num', ',' . $luck_num)
                ->where('luck_user_id', 'NEQ', $this->user_id)
                ->page($this->page, 10)
                ->select();
            if($result){
                return json(['status' => 200, 'msg' => $result]);
            }else{
                return json(['status' => 200, 'msg' => []]);
            }
        }else{
            return json(['status' => 0, 'msg' => '数据更新失败']);
        }
    }
    
    /**
     * 幸运数字回显
     * @return \think\response\Json
     */
    public function showLuck(){
        $luck_num = Db::table('up_luck')->where('luck_user_id', $this->user_id)->value('luck_num');
        if($luck_num){
            $show_num = ltrim($luck_num, ',');
            return json(['status' => 200, 'msg' => $show_num]);
        }else{
            return json(['status' => 200, 'msg' => '']);
        }
    }
    
    /**
     * 用于查看我的评论回复点赞时修改已读/未读状态
     * @return \think\response\Json
     * change_type   改变的类型    1 评论   2 回复   3 点赞
     * subject_id    对象ID
     */
    public function changeReadStatus(){
        $change_type = input('change_type'); // 1 评论  2 回复  3 点赞
        $subject_id = input('subject_id'); // 对象ID
        $where = [];
        if($change_type == 1){
            $table = 'up_comment';
            $where['comment_id'] = $subject_id;
        }elseif($change_type == 2){
            $table = 'up_comment_reply';
            $where['comment_reply_id'] = $subject_id;
        }else{
            $table = 'up_comment_give';
            $where['give_id'] = $subject_id;
        }
        $res = Db::table($table)->where($where)->setField('is_readed', 2);
        if($res){
            return json(['status' => 200, 'msg' => '']);
        }else{
            return json(['status' => 0, 'msg' => '']);
        }
    }
    
    /**
     * 用于账号切换时判断/更新用户的最后登录时间
     * @return \think\response\Json
     * choosed_id   选择登录的账号ID
     */
    public function isPasted(){
        $choosed_id = input('choosed_id');
        // 先更新当前登录的最后登录时间
        Db::table('up_u_user')->where('user_id', $this->user_id)->update(['user_last_time' => date('Y-m-d H:i:s')]);
        
        // 查询选择登录的用户，距离上次登录时间是否超过10天
        $last_time_str = Db::table('up_u_user')->where('user_id', $choosed_id)->value('user_last_time');
        $last_time = strtotime($last_time_str);
        $ten_ago = strtotime('-10 days');
        if($last_time < $ten_ago){
            return json(['status' => 111, 'msg' => '距上次登录时间超过10天，请重新登录']);
        }
        // 如果不超过10天，则更新用户登录时间
        $res = Db::table('up_u_user')->where('user_id', $choosed_id)->update(['user_last_time' => date('Y-m-d H:i:s')]);
        if($res){
            $user = Db::table('up_u_user')->where('user_id', $choosed_id)->find();
            $rytoken = $this->rongyun($user['user_id'],'who',$user['user_image']);
            $user['rytoken'] = $rytoken['token'];
            return json(['status' => 200, 'msg' => $user]);
        }else{
            return json(['status' => 0, 'msg' => '该账号是当前登录账号']);
        }
    }
    
    /**
     * 日期时间样式
     * @param $time    时间戳
     * @return false|string
     */
    private function showTime($time){
        // 时间显示
        $beginTime = strtotime(date('Y-m-d 00:00:00')); // 今天的开始时间
        $thisYear = date('Y'); // 本年
        $sendYear = date('Y', $time); // 发布的年份
        $time_return = '';
        // 本年
        if($thisYear == $sendYear){
            $time_return = date('m-d', $time);
        }
        // 非本年
        if($sendYear < $thisYear){
            $time_return = date('Y-m-d', $time);
        }
        // 本日
        if($time >= $beginTime){
            $time_return = date('H:i', $time);
        }
        return $time_return;
    }
    
    /**
     * 用户信息
     * @param $field   字段
     * @return array|false|\PDOStatement|string|\think\Model
     */
    private function userInfo($field){
        $info = Db::table('up_u_user')
            ->where('user_id', $this->user_id)
            ->field($field)
            ->find();
        return $info;
    }
    
    /**
     * 地区字符串
     * @param $sheng       省份
     * @param $shi         城市
     * @param string $qu   地区
     * @return string
     */
    private function districtStr($sheng, $shi, $qu){
        $shengName = Db::name('area')->where('district_id', $sheng)->value('district');
        $shiName = Db::name('area')->where('district_id', $shi)->value('district');
        $quName = Db::name('area')->where('district_id', $qu)->value('district');
        $str = $shengName . ' ' . $shiName . ' ' . $quName;
        return $str;
    }
}